# The compiler. This is not portable and
# should be edited or have the entire build
# system replaced.
CC=gcc

# Compiler flags.
CCFLAGS=-c -Wall

# Include directory.
INC=-Ipubinc

all: crz clean
	mkdir build
	mkdir build/obj
	mkdir build/lib
	mkdir build/bin
	mv *.o build/obj
	mv *.a build/lib

crz: crz_serialize.o crz_deserialize.o crz_utils.o
	ar -cvq libcrz.a Crz_Serialize.o Crz_Deserialize.o Crz_Utils.o 

crz_utils.o:
	$(CC) $(CCFLAGS) $(INC) src/Crz_Utils.c

crz_deserialize.o:
	$(CC) $(CCFLAGS) $(INC) src/Crz_Deserialize.c

crz_serialize.o:
	$(CC) $(CCFLAGS) $(INC) src/Crz_Serialize.c

tests: test_crz_utils.o test_crz_serialize.o
	$(CC) $(INC) -Lbuild/lib test_crz_utils.o -o test_crz_utils -lcrz 
	$(CC) $(INC) -Lbuild/lib test_crz_serialize.o -o test_crz_serialize -lcrz 
	mv test_* build/bin

test_crz_utils.o:
	$(CC) $(CCFLAGS) $(INC) tests/src/test_crz_utils.c

test_crz_serialize.o:
	$(CC) $(CCFLAGS) $(INC) tests/src/test_crz_serialize.c

clean:
	rm -rf build
